/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modulos.consulta.oftalmologia.vista;

import basedatos.OperacionesBD;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import modulos.agenda.vista.iFrmAgenda;
import modulos.consulta.oftalmologia.modelo.RecetaOftalmologia;
import modulos.paciente.modelo.Paciente;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.view.JasperViewer;
import vista.frmPrincipal;
import vista.modelo.Mensaje;
import vista.modelo.OperacionesVarias;

/**
 *
 * @author medikux
 */
public class iFrmRecetaLentesOftalmologia extends javax.swing.JInternalFrame {

    RecetaOftalmologia receta;
    Paciente paciente;
    private int tipo = 0;
    boolean actualizaTabla = false;

    /**
     * Creates new form iFrmRecetaLentes
     */
    public iFrmRecetaLentesOftalmologia() {
        initComponents();
    }

    public iFrmRecetaLentesOftalmologia(Paciente p) {
        initComponents();
        OperacionesVarias.centrar(this);
        paciente = p;
        txtNombrePaciente.setText(paciente.getNombre() + " " + paciente.getApellido());
        txtFecha.setText(new SimpleDateFormat("dd 'de' MMMM 'del' yyyy").format(new Date()));
        actualizaTabla = true;
    }

    public iFrmRecetaLentesOftalmologia(RecetaOftalmologia ro, Paciente p) {
        initComponents();
        OperacionesVarias.centrar(this);
        receta = ro;
        paciente = p;
        llenaCampos();
    }

    public iFrmRecetaLentesOftalmologia(RecetaOftalmologia ro, Paciente p, int t) {
        initComponents();
        OperacionesVarias.centrar(this);
        receta = ro;
        paciente = p;
        tipo = t;
        llenaCampos();
    }

    private void llenaCampos() {
        txtNombrePaciente.setText(paciente.getNombre() + " " + paciente.getApellido());
        txtFecha.setText(new SimpleDateFormat("dd 'de' MMMM 'del' yyyy").format(new Date()));
        txtAdicionOD.setText(receta.getAdicionOD());
        txtAdicionOI.setText(receta.getAdicionOI());
        txtDistanciaCilOD.setText(receta.getDistCilOD());
        txtDistanciaCilOI.setText(receta.getDistCilOI());
        txtDistanciaDiOD.setText(receta.getDistDiOD());
        txtDistanciaDiOI.setText(receta.getDistDiOI());
        txtDistanciaDnpOD.setText(receta.getDistDnpOD());
        txtDistanciaDnpOI.setText(receta.getDistDnpOI());
        txtDistanciaEjeOD.setText(receta.getDistEjeOD());
        txtDistanciaEjeOI.setText(receta.getDistEjeOI());
        txtDistanciaEsfOD.setText(receta.getDistEsfOD());
        txtDistanciaEsfOI.setText(receta.getDistEsfOI());
        txtDistanciaPrismaOD.setText(receta.getDistPrismaOD());
        txtDistanciaPrismaOI.setText(receta.getDistPrismaOI());
        txtAdicionOD.setText(receta.getAdicionOD());
        txtAdicionOI.setText(receta.getAdicionOI());
        txtLecturaCilOD.setText(receta.getLectCilOD());
        txtLecturaCilOI.setText(receta.getLectCilOI());
        txtLecturaDiOD.setText(receta.getLectDiOD());
        txtLecturaDiOI.setText(receta.getLectDiOI());
        txtLecturaDnpOD.setText(receta.getLectDnpOD());
        txtLecturaDnpOI.setText(receta.getLectDnpOI());
        txtLecturaEjeOD.setText(receta.getLectEjeOD());
        txtLecturaEjeOI.setText(receta.getLectEjeOI());
        txtLecturaEsfOD.setText(receta.getLectEsfOD());
        txtLecturaEsfOI.setText(receta.getLectEsfOI());
        txtLecturaPrismaOD.setText(receta.getLectPrismaOD());
        txtLecturaPrismaOI.setText(receta.getLectPrismaOI());
        if (tipo > 0) {
            txtAltura.setText(receta.getAltura());
            txtColor.setText(receta.getColor());
            txtMaterial.setText(receta.getMaterial());
            txtObservaciones.setText(receta.getObservaciones());
            btnGuardar.setText("Modificar");
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        btnCerrar = new javax.swing.JButton();
        btnGuardar = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        txtDistanciaCilOI = new javax.swing.JTextField();
        txtDistanciaCilOD = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        txtDistanciaEjeOD = new javax.swing.JTextField();
        txtDistanciaEjeOI = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        txtDistanciaEsfOD = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        txtDistanciaDiOD = new javax.swing.JTextField();
        txtDistanciaDnpOD = new javax.swing.JTextField();
        txtDistanciaDnpOI = new javax.swing.JTextField();
        txtDistanciaPrismaOI = new javax.swing.JTextField();
        txtDistanciaDiOI = new javax.swing.JTextField();
        txtDistanciaPrismaOD = new javax.swing.JTextField();
        txtDistanciaEsfOI = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        txtLecturaCilOI = new javax.swing.JTextField();
        txtLecturaCilOD = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        txtLecturaEjeOD = new javax.swing.JTextField();
        txtLecturaEjeOI = new javax.swing.JTextField();
        jLabel21 = new javax.swing.JLabel();
        txtLecturaEsfOD = new javax.swing.JTextField();
        jLabel22 = new javax.swing.JLabel();
        txtLecturaDiOD = new javax.swing.JTextField();
        txtLecturaDnpOD = new javax.swing.JTextField();
        txtLecturaDnpOI = new javax.swing.JTextField();
        txtLecturaPrismaOI = new javax.swing.JTextField();
        txtLecturaDiOI = new javax.swing.JTextField();
        txtLecturaPrismaOD = new javax.swing.JTextField();
        txtLecturaEsfOI = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        jLabel24 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        jLabel26 = new javax.swing.JLabel();
        txtAdicionOD = new javax.swing.JTextField();
        txtAdicionOI = new javax.swing.JTextField();
        jLabel27 = new javax.swing.JLabel();
        jLabel28 = new javax.swing.JLabel();
        jLabel29 = new javax.swing.JLabel();
        txtAltura = new javax.swing.JTextField();
        jLabel30 = new javax.swing.JLabel();
        txtObservaciones = new javax.swing.JTextField();
        txtMaterial = new javax.swing.JTextField();
        txtColor = new javax.swing.JTextField();
        jLabel31 = new javax.swing.JLabel();
        jLabel32 = new javax.swing.JLabel();
        txtNombrePaciente = new javax.swing.JTextField();
        txtFecha = new javax.swing.JTextField();
        btnImprimir = new javax.swing.JButton();

        setClosable(true);
        setTitle("RECETA DE LENTES");
        setVisible(true);
        getContentPane().setLayout(null);

        jLabel1.setFont(new java.awt.Font("DejaVu Sans", 1, 13)); // NOI18N
        jLabel1.setText("Paciente:");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(12, 25, 69, 17);

        jLabel2.setFont(new java.awt.Font("DejaVu Sans", 1, 13)); // NOI18N
        jLabel2.setText("Fecha:");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(12, 54, 49, 17);
        getContentPane().add(jLabel8);
        jLabel8.setBounds(412, 52, 213, 0);

        btnCerrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jpgs/agt_home.png"))); // NOI18N
        btnCerrar.setText("Cerrar");
        getContentPane().add(btnCerrar);
        btnCerrar.setBounds(290, 590, 110, 30);

        btnGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jpgs/filesave.png"))); // NOI18N
        btnGuardar.setText("Guardar");
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });
        getContentPane().add(btnGuardar);
        btnGuardar.setBounds(160, 590, 120, 30);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "DISTANCIA", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("DejaVu Sans Condensed", 3, 14), new java.awt.Color(57, 99, 163))); // NOI18N

        jLabel13.setText("D.I.");

        jLabel12.setText("PRISMA");

        jLabel10.setText("CIL");

        jLabel11.setText("EJE");

        jLabel9.setText("ESF");

        jLabel14.setText("DNP");

        jLabel4.setFont(new java.awt.Font("DejaVu Sans", 1, 13)); // NOI18N
        jLabel4.setText("O.I:");

        jLabel3.setFont(new java.awt.Font("DejaVu Sans", 1, 13)); // NOI18N
        jLabel3.setText("O.D:");

        jLabel15.setFont(new java.awt.Font("DejaVu Sans", 0, 10)); // NOI18N
        jLabel15.setText("mm");

        jLabel16.setFont(new java.awt.Font("DejaVu Sans", 0, 10)); // NOI18N
        jLabel16.setText("mm");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(57, 57, 57)
                        .addComponent(jLabel9))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(67, 67, 67)
                                .addComponent(jLabel10)
                                .addGap(39, 39, 39)
                                .addComponent(jLabel11)
                                .addGap(26, 26, 26)
                                .addComponent(jLabel12)
                                .addGap(26, 26, 26)
                                .addComponent(jLabel13)
                                .addGap(27, 27, 27)
                                .addComponent(jLabel14))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtDistanciaEsfOD, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtDistanciaEsfOI, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtDistanciaCilOD, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtDistanciaCilOI, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtDistanciaEjeOD, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtDistanciaEjeOI, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtDistanciaPrismaOD, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtDistanciaPrismaOI, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGap(12, 12, 12)
                                        .addComponent(jLabel15))
                                    .addComponent(txtDistanciaDiOD, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtDistanciaDiOI, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGap(12, 12, 12)
                                        .addComponent(jLabel16))
                                    .addComponent(txtDistanciaDnpOD, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtDistanciaDnpOI, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))))))
                .addContainerGap(24, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(jLabel9)
                    .addComponent(jLabel11)
                    .addComponent(jLabel12)
                    .addComponent(jLabel13)
                    .addComponent(jLabel14))
                .addGap(1, 1, 1)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtDistanciaEsfOD, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3))
                        .addGap(18, 18, 18)
                        .addComponent(jLabel4))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(txtDistanciaCilOD, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtDistanciaCilOI, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtDistanciaEsfOI, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(txtDistanciaEjeOD, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtDistanciaEjeOI, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(txtDistanciaPrismaOD, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(txtDistanciaDiOD, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtDistanciaDiOI, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtDistanciaPrismaOI, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel15))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(txtDistanciaDnpOD, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtDistanciaDnpOI, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel16))))
        );

        getContentPane().add(jPanel1);
        jPanel1.setBounds(12, 81, 422, 148);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "LECTURA", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("DejaVu Sans Condensed", 3, 14), new java.awt.Color(57, 99, 163))); // NOI18N

        jLabel17.setText("D.I.");

        jLabel18.setText("PRISMA");

        jLabel19.setText("CIL");

        jLabel20.setText("EJE");

        jLabel21.setText("ESF");

        jLabel22.setText("DNP");

        jLabel5.setFont(new java.awt.Font("DejaVu Sans", 1, 13)); // NOI18N
        jLabel5.setText("O.I:");

        jLabel6.setFont(new java.awt.Font("DejaVu Sans", 1, 13)); // NOI18N
        jLabel6.setText("O.D:");

        jLabel23.setFont(new java.awt.Font("DejaVu Sans", 0, 10)); // NOI18N
        jLabel23.setText("mm");

        jLabel24.setFont(new java.awt.Font("DejaVu Sans", 0, 10)); // NOI18N
        jLabel24.setText("mm");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(57, 57, 57)
                        .addComponent(jLabel21))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(67, 67, 67)
                                .addComponent(jLabel19)
                                .addGap(39, 39, 39)
                                .addComponent(jLabel20)
                                .addGap(26, 26, 26)
                                .addComponent(jLabel18)
                                .addGap(26, 26, 26)
                                .addComponent(jLabel17)
                                .addGap(27, 27, 27)
                                .addComponent(jLabel22))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtLecturaEsfOD, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtLecturaEsfOI, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtLecturaCilOD, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtLecturaCilOI, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtLecturaEjeOD, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtLecturaEjeOI, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtLecturaPrismaOD, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtLecturaPrismaOI, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addGap(12, 12, 12)
                                        .addComponent(jLabel23))
                                    .addComponent(txtLecturaDiOD, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtLecturaDiOI, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addGap(12, 12, 12)
                                        .addComponent(jLabel24))
                                    .addComponent(txtLecturaDnpOD, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtLecturaDnpOI, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))))))
                .addContainerGap(24, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel19)
                    .addComponent(jLabel21)
                    .addComponent(jLabel20)
                    .addComponent(jLabel18)
                    .addComponent(jLabel17)
                    .addComponent(jLabel22))
                .addGap(1, 1, 1)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtLecturaEsfOD, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addGap(18, 18, 18)
                        .addComponent(jLabel5))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(txtLecturaCilOD, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtLecturaCilOI, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtLecturaEsfOI, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(txtLecturaEjeOD, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtLecturaEjeOI, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(txtLecturaPrismaOD, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(txtLecturaDiOD, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtLecturaDiOI, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtLecturaPrismaOI, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel23))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(txtLecturaDnpOD, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtLecturaDnpOI, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel24))))
        );

        getContentPane().add(jPanel2);
        jPanel2.setBounds(12, 300, 422, 148);

        jLabel7.setFont(new java.awt.Font("DejaVu Sans Condensed", 3, 13)); // NOI18N
        jLabel7.setForeground(new java.awt.Color(57, 99, 163));
        jLabel7.setText("ADICION");
        getContentPane().add(jLabel7);
        jLabel7.setBounds(125, 254, 56, 17);

        jLabel25.setFont(new java.awt.Font("DejaVu Sans", 1, 13)); // NOI18N
        jLabel25.setText("O.D:");
        getContentPane().add(jLabel25);
        jLabel25.setBounds(197, 229, 32, 17);

        jLabel26.setFont(new java.awt.Font("DejaVu Sans", 1, 13)); // NOI18N
        jLabel26.setText("O.I:");
        getContentPane().add(jLabel26);
        jLabel26.setBounds(198, 279, 25, 17);
        getContentPane().add(txtAdicionOD);
        txtAdicionOD.setBounds(241, 227, 63, 30);
        getContentPane().add(txtAdicionOI);
        txtAdicionOI.setBounds(241, 270, 63, 30);

        jLabel27.setFont(new java.awt.Font("DejaVu Sans", 1, 11)); // NOI18N
        jLabel27.setText("Material:");
        getContentPane().add(jLabel27);
        jLabel27.setBounds(12, 467, 70, 14);

        jLabel28.setFont(new java.awt.Font("DejaVu Sans", 1, 11)); // NOI18N
        jLabel28.setText("Color:");
        getContentPane().add(jLabel28);
        jLabel28.setBounds(12, 501, 38, 14);

        jLabel29.setFont(new java.awt.Font("DejaVu Sans", 1, 11)); // NOI18N
        jLabel29.setText("Altura:");
        getContentPane().add(jLabel29);
        jLabel29.setBounds(12, 528, 100, 20);
        getContentPane().add(txtAltura);
        txtAltura.setBounds(120, 520, 310, 30);

        jLabel30.setFont(new java.awt.Font("DejaVu Sans", 1, 11)); // NOI18N
        jLabel30.setText("Observaciones:");
        getContentPane().add(jLabel30);
        jLabel30.setBounds(12, 559, 100, 20);
        getContentPane().add(txtObservaciones);
        txtObservaciones.setBounds(120, 550, 310, 30);
        getContentPane().add(txtMaterial);
        txtMaterial.setBounds(120, 460, 310, 30);
        getContentPane().add(txtColor);
        txtColor.setBounds(120, 490, 310, 30);

        jLabel31.setFont(new java.awt.Font("DialogInput", 3, 13)); // NOI18N
        jLabel31.setForeground(new java.awt.Color(57, 99, 163));
        jLabel31.setText("Nombres");
        getContentPane().add(jLabel31);
        jLabel31.setBounds(134, 0, 80, 17);

        jLabel32.setFont(new java.awt.Font("DialogInput", 3, 13)); // NOI18N
        jLabel32.setForeground(new java.awt.Color(57, 99, 163));
        jLabel32.setText("Apellidos");
        getContentPane().add(jLabel32);
        jLabel32.setBounds(277, 0, 90, 17);
        getContentPane().add(txtNombrePaciente);
        txtNombrePaciente.setBounds(93, 23, 307, 30);
        getContentPane().add(txtFecha);
        txtFecha.setBounds(93, 52, 307, 30);

        btnImprimir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jpgs/printer1.png"))); // NOI18N
        btnImprimir.setText("Imprimir");
        btnImprimir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnImprimirActionPerformed(evt);
            }
        });
        getContentPane().add(btnImprimir);
        btnImprimir.setBounds(50, 590, 100, 30);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-451)/2, (screenSize.height-650)/2, 451, 650);
    }// </editor-fold>//GEN-END:initComponents

    private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
        if (!camposVacios()) {
            if (receta == null) {
                receta = new RecetaOftalmologia();
            }
            setReceta();
            if (btnGuardar.getText().equals("Guardar")) {
                if (OperacionesBD.guardar(receta)) {
                    Mensaje.datosGuardados();
                    if (actualizaTabla) {
                        iFrmListaRecetaOftalmologia.listarRecetas();
                        iFrmListaRecetaOftalmologia.modeloTabla();
                    }
                    dispose();
                } else {
                    Mensaje.datosNoGuardados();
                }
            } else if (btnGuardar.getText().equals("Modificar")) {
                if (OperacionesBD.modificar(receta)) {
                    Mensaje.datosModificados();
                    if (actualizaTabla) {
                        iFrmListaRecetaOftalmologia.listarRecetas();
                        iFrmListaRecetaOftalmologia.modeloTabla();
                    }
                    dispose();
                } else {
                    Mensaje.datosNoModificados();
                }
            }
        } else {
            Mensaje.camposVacios();
        }
    }//GEN-LAST:event_btnGuardarActionPerformed

    private void btnImprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnImprimirActionPerformed
        receta= new RecetaOftalmologia();
        setReceta();
        Map<String, Object> parametros = new HashMap<>();
        parametros.put("NOMBRE", receta.getPaciente().getNombre());
        parametros.put("ESF_OD", receta.getDistEsfOD());
        parametros.put("ESF_OI", receta.getDistEsfOD());
        ArrayList aux = new ArrayList();
        aux.add("aux");
        try {

            JasperReport reporte = (JasperReport) JRLoader.loadObject(getClass().getResource("/modulos/reportes/receta/oftalmologia/RecetaOftalmologia.jasper"));
            JasperPrint jasperPrint = JasperFillManager.fillReport(reporte, parametros, new JRBeanCollectionDataSource(aux));
            JasperViewer vista = new JasperViewer(jasperPrint, false);
            vista.setSize(frmPrincipal.dskpPrincipal.size());
            vista.setVisible(true);
        } catch (JRException ex) {
            Logger.getLogger(iFrmAgenda.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btnImprimirActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCerrar;
    private javax.swing.JButton btnGuardar;
    private javax.swing.JButton btnImprimir;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTextField txtAdicionOD;
    private javax.swing.JTextField txtAdicionOI;
    private javax.swing.JTextField txtAltura;
    private javax.swing.JTextField txtColor;
    private javax.swing.JTextField txtDistanciaCilOD;
    private javax.swing.JTextField txtDistanciaCilOI;
    private javax.swing.JTextField txtDistanciaDiOD;
    private javax.swing.JTextField txtDistanciaDiOI;
    private javax.swing.JTextField txtDistanciaDnpOD;
    private javax.swing.JTextField txtDistanciaDnpOI;
    private javax.swing.JTextField txtDistanciaEjeOD;
    private javax.swing.JTextField txtDistanciaEjeOI;
    private javax.swing.JTextField txtDistanciaEsfOD;
    private javax.swing.JTextField txtDistanciaEsfOI;
    private javax.swing.JTextField txtDistanciaPrismaOD;
    private javax.swing.JTextField txtDistanciaPrismaOI;
    private javax.swing.JTextField txtFecha;
    private javax.swing.JTextField txtLecturaCilOD;
    private javax.swing.JTextField txtLecturaCilOI;
    private javax.swing.JTextField txtLecturaDiOD;
    private javax.swing.JTextField txtLecturaDiOI;
    private javax.swing.JTextField txtLecturaDnpOD;
    private javax.swing.JTextField txtLecturaDnpOI;
    private javax.swing.JTextField txtLecturaEjeOD;
    private javax.swing.JTextField txtLecturaEjeOI;
    private javax.swing.JTextField txtLecturaEsfOD;
    private javax.swing.JTextField txtLecturaEsfOI;
    private javax.swing.JTextField txtLecturaPrismaOD;
    private javax.swing.JTextField txtLecturaPrismaOI;
    private javax.swing.JTextField txtMaterial;
    private javax.swing.JTextField txtNombrePaciente;
    private javax.swing.JTextField txtObservaciones;
    // End of variables declaration//GEN-END:variables

    private void setReceta() {
        receta.setDistCilOD(txtDistanciaCilOD.getText());
        receta.setDistCilOI(txtDistanciaCilOI.getText());
        receta.setDistDiOD(txtDistanciaDiOD.getText());
        receta.setDistDiOI(txtDistanciaDiOI.getText());
        receta.setDistDnpOD(txtDistanciaDnpOD.getText());
        receta.setDistDnpOI(txtDistanciaDnpOI.getText());
        receta.setDistEjeOD(txtDistanciaEjeOD.getText());
        receta.setDistEjeOI(txtDistanciaEjeOI.getText());
        receta.setDistEsfOD(txtDistanciaEsfOD.getText());
        receta.setDistEsfOI(txtDistanciaEsfOI.getText());
        receta.setDistPrismaOD(txtDistanciaPrismaOD.getText());
        receta.setDistPrismaOI(txtDistanciaPrismaOI.getText());
        receta.setAdicionOD(txtAdicionOD.getText());
        receta.setAdicionOI(txtAdicionOI.getText());
        receta.setLectCilOD(txtLecturaCilOD.getText());
        receta.setLectCilOI(txtLecturaCilOI.getText());
        receta.setLectDiOD(txtLecturaDiOD.getText());
        receta.setLectDiOI(txtLecturaDiOI.getText());
        receta.setLectDnpOD(txtLecturaDnpOD.getText());
        receta.setLectDnpOI(txtLecturaDnpOI.getText());
        receta.setLectEjeOD(txtLecturaEjeOD.getText());
        receta.setLectEjeOI(txtLecturaEjeOI.getText());
        receta.setLectEsfOD(txtLecturaEsfOD.getText());
        receta.setLectEsfOI(txtLecturaEsfOI.getText());
        receta.setLectPrismaOD(txtLecturaPrismaOD.getText());
        receta.setLectPrismaOI(txtLecturaPrismaOI.getText());
        receta.setMaterial(txtMaterial.getText());
        receta.setAltura(txtAltura.getText());
        receta.setColor(txtColor.getText());
        receta.setObservaciones(txtObservaciones.getText());
        receta.setPaciente(paciente);
        receta.setFechaReceta(Calendar.getInstance().getTime());
    }

    private boolean camposVacios() {
        if (txtDistanciaCilOD.getText().isEmpty() || txtDistanciaCilOI.getText().isEmpty()
                || txtDistanciaDiOD.getText().isEmpty() || txtDistanciaDiOI.getText().isEmpty()
                || txtDistanciaDnpOD.getText().isEmpty() || txtDistanciaDnpOI.getText().isEmpty()
                || txtDistanciaEjeOD.getText().isEmpty() || txtDistanciaEjeOI.getText().isEmpty()
                || txtDistanciaEsfOD.getText().isEmpty() || txtDistanciaEsfOI.getText().isEmpty()
                || txtDistanciaPrismaOD.getText().isEmpty() || txtDistanciaPrismaOI.getText().isEmpty()
                || txtAdicionOD.getText().isEmpty() || txtAdicionOI.getText().isEmpty()
                || txtLecturaCilOD.getText().isEmpty() || txtLecturaCilOI.getText().isEmpty()
                || txtLecturaDiOD.getText().isEmpty() || txtLecturaDiOI.getText().isEmpty()
                || txtLecturaDnpOD.getText().isEmpty() || txtLecturaDnpOI.getText().isEmpty()
                || txtLecturaEjeOD.getText().isEmpty() || txtLecturaEjeOI.getText().isEmpty()
                || txtLecturaEsfOD.getText().isEmpty() || txtLecturaEsfOI.getText().isEmpty()
                || txtLecturaPrismaOD.getText().isEmpty() || txtLecturaPrismaOI.getText().isEmpty()) {
            return true;
        } else {
            return false;
        }
    }
}
